import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { isProd } from './const';
import { ConfigModule } from './modules/config/config.module';
import { PermissionControlModule } from './modules/permission-control/permission-control.module';
import { PermissionModule } from './modules/permission/permission.module';
import { RoleModule } from './modules/role/role.module';

@Module({
  imports: [
    ConfigModule,
    // todo 使用 dotenv 从 env 文件中读取
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: '47.96.94.163',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'permission_tool',
      entities: [__dirname + `/../**/*.entity.${isProd ? 'j' : 't'}s`],
      logging: ['error'],
      synchronize: true,
    }),
    PermissionModule,
    RoleModule,
    PermissionControlModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
